﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using XStudio.WebFramework.Mvc.Filter;
using XStudio.Framework.Extensions;
using XStudio.Core.Ext.ConvertExtensions;
using Core.Manage.Product;
using XStudio.WebFramework.Support;

namespace Admin.Areas.Product.Controllers
{
    [AuthorizeFilter]
    [Description("生资产品")]

    public class GoodsController : Controller
    {
        #region 获取生资产品类型表
        /// <summary>
        /// 获取生资产品类型表
        /// </summary>
        /// <returns></returns>
        [AuthorizeFilter(true)]
        [Description("生资产品列表")]
        public ActionResult List(int type)
        {
            ViewBag.Type = type;
            return View();
        }

        /// <summary>
        /// 按条件查询列表信息
        /// </summary>
        /// <returns></returns>
        [AuthorizeFilter(true)]
        [HttpPost]
        public ActionResult ListData(int type)
        {
            int pageNo = Request["page"].ToInt32();
            if (pageNo < 1)
                pageNo = 1;
            int pageSize = Request["rows"].ToInt32();
            if (pageSize < 10)
                pageSize = 30;
            var searchCondition = " 1=1 and ApplyStatus=" + type;

            //搜索条件
            if (!string.IsNullOrWhiteSpace(Request["SearchWord"]))
            {
                var searchWord = Request["SearchWord"].LikeFilter();
                searchCondition += string.Format(" AND (IMEI LIKE '%{0}%')", searchWord);
            }

            var data = GoodsVWRule.Instance.GetGridDataByPage(pageSize, pageNo - 1, true, searchCondition);
            return Json(data, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region 审核
        [Description("审核")]
        public ActionResult Apply(int id, int type)
        {
            var entity = new GoodsEntity()
            {
                ApplyStatus = type
            };

            return Json(GoodsRule.Instance.Update(entity, t => t.UID == id), JsonRequestBehavior.AllowGet);
        }
        #endregion
    }
}